﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace PloobsEngine.SceneControl
{
    public class GlowPostEffect : IPostEffect
    {

        Effect effect = null;        
        EngineStuff engine;                
        RenderTarget2D target;
        RenderTarget2D target2;  
        GaussianBlurPostEffect gbp;
        Texture2D x;

        private float intensity = 1;

        public float Intensity
        {
            get { return intensity; }
            set { intensity = value; }
        }
        
        public void Draw(IRenderHelper rHelper, Microsoft.Xna.Framework.GameTime gt, Microsoft.Xna.Framework.Rectangle screenRec, IWorld world)
        {         
             rHelper.SetUpRenderTarget(target);
             gbp.Draw(rHelper[PrincipalConstants.extra1RT], rHelper,  gt, screenRec, world);
             x = rHelper.GetResultsRenderTarget();

             //rHelper.SetUpRenderTarget(target2);
             //gbp.Draw(x, rHelper, gt, screenRec, world);
             //x = rHelper.GetResultsRenderTarget();

             effect.Parameters["intensity"].SetValue(intensity);
             effect.Parameters["glowMapBlurried"].SetValue(x);
             effect.Parameters["colorMap"].SetValue(rHelper[PrincipalConstants.CurrentImage]);
             effect.Parameters["halfPixel"].SetValue(EngineStuff.HalfPixel);             
             rHelper.RenderTextureToFullScreenVertexPixel(effect);                         
         
        }

        public void init(EngineStuff engine)
        {
            target = EngineStuff.GetDefaultBuffer(EngineStuff.BackBufferWidth, EngineStuff.BackBufferHeight, SurfaceFormat.Color);
            target2 = EngineStuff.GetDefaultBuffer(EngineStuff.BackBufferWidth, EngineStuff.BackBufferHeight, SurfaceFormat.Color);            
            effect = EngineStuff.InternalContentManager.GetAsset<Effect>("glowPost");            
            gbp = new GaussianBlurPostEffect();
            (gbp as IPostEffect).init(engine);
            this.engine = engine;            

        }

    }
}


